<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Db;
use think\Validate;


/**
 * 定时预约班车
 * Class Entryapply
 * @package app\api\controller
 */
class Busrecord extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Busrecord;
        $this->bus_model = new \app\admin\model\Bus;
    }

    public function index()
    {
        $noreserve_arr = [
            ['nickname'=>'王峰','tel'=>'200301082',],
            ['nickname'=>'李考年','tel'=>'198501008',],
            ['nickname'=>'王磊','tel'=>'199401022',],
            ['nickname'=>'王天龙','tel'=>'200101051',],
            ['nickname'=>'孙景福','tel'=>'199701028',],
            ['nickname'=>'张友民','tel'=>'199701040',],
            ['nickname'=>'陶飞','tel'=>'199701042',],
            ['nickname'=>'刁志凯','tel'=>'200401014',],
            ['nickname'=>'于经','tel'=>'200301108',],
            ['nickname'=>'尉霖','tel'=>'200401118',],
            ['nickname'=>'邓勇刚','tel'=>'200501121',],
            ['nickname'=>'赵显波','tel'=>'200301118',],
            ['nickname'=>'孙玉林','tel'=>'199701031',],
            ['nickname'=>'史晓文','tel'=>'200301067',],
            ['nickname'=>'杨若迪','tel'=>'202001049',],
            ['nickname'=>'丁志勇','tel'=>'202001050',],
            ['nickname'=>'李沛霞','tel'=>'202001037',],
            ['nickname'=>'陶珊珊','tel'=>'202001055',],
            ['nickname'=>'李奇','tel'=>'201801073',],
            ['nickname'=>'刘文庭','tel'=>'202001051',],
            ['nickname'=>'刘翔宇','tel'=>'201501021',],
            ['nickname'=>'王玉堃','tel'=>'201901126',],
            ['nickname'=>'刘源','tel'=>'202001034',],
            ['nickname'=>'李超','tel'=>'200601103',],
            ['nickname'=>'王春晓','tel'=>'201801075',],
            ['nickname'=>'李振荣','tel'=>'202001036',],
            ['nickname'=>'李虹俐','tel'=>'201801064',],
            ['nickname'=>'白芳','tel'=>'201901052',],
            ['nickname'=>'梁超','tel'=>'201801069',],
            ['nickname'=>'孟新翔','tel'=>'202001046',],
            ['nickname'=>'赵振达','tel'=>'197501003',],
        ];
        foreach ($noreserve_arr as $key => $v)
        {
            $go_pingdu = $this->bus_model->where('type=1')->order('id asc')->find();
            $back_chengyang = $this->bus_model->where('type=2 and times!="不回城阳"')->order('id desc')->find();
            $params = array();
            $params['nickname'] = $v['nickname'];
            $params['tel'] = $v['tel'];
            $params['check_time'] = strtotime(date('Y-m-d',strtotime("+1 days")));
            $params['type'] = 1;
            $params['time_slot'] = $go_pingdu['id'];
            $params['time_slot2'] = $back_chengyang['id'];
            $params['times'] = $go_pingdu['times'];
            $params['times2'] =$back_chengyang['times'];
            $where['tel'] = $v['tel'];
            $where['nickname'] = $v['nickname'];
            $where['check_time'] = strtotime(date('Y-m-d',strtotime("+1 days")));
            $info = $this->model->where($where)->find();
            if(isset($info)){
                $row= $this->model->get($info['id']);
                $ret = $row->save($params);
            }else{
                \app\admin\model\Busrecord::create($params);
                // $ret = $this->model->save($params);
            }
        }
    }

}